package com.software.aperture.controller;


import com.software.aperture.bean.Commit;
import com.software.aperture.repository.CommitRe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class CommitController {
    @Autowired
    private CommitRe commitRe;
    static Integer num=6;
    /**
     * 查找所有评论
     */
    @GetMapping(value = "/commits")
    public List<Commit> findCommits()
    {
        return commitRe.findAll();
    }
    /**
     * 插入评论
     */
    @PostMapping(value = "/addcommit")
    public void AddCommit(HttpServletRequest request)
    {
        String commit=request.getParameter("CommitConent");
        Commit commit1=new Commit();
        commit1.setCommitid(num++);
        commit1.setCommitcontent(commit);
        commit1.setCommitnumber(commit.length());
        commit1.setCommitpublisherid(num++);
        commit1.setCommittype("wf");
        commitRe.save(commit1);
    }
}
